﻿using System;
using System.Drawing;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Globalization;
using System.Text;
using System.Collections;

namespace VSM
{
    public partial class DealerWSC : System.Web.UI.Page
    {
        private static DataTable dtContents;
        private static GeneralFunctions GF = null;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {

            if (Session[Utils.AppConstants.ID_User] == null
                          || Session[Utils.AppConstants.Password] == null
                          || Session[Utils.AppConstants.ID_Dealer] == null)
            {
                Response.Redirect("../../Login.aspx");
            }
            if (!IsPostBack)
            {
                DateTime firstDate = DateTime.Today.AddDays(1 - DateTime.Today.Day);
                DateTime firstDateNextMonth = firstDate.AddMonths(1);
                DateTime lastDate = firstDateNextMonth.AddDays(-1);

                txtFromDate.Text = firstDate.ToString("dd/MM/yyyy");
                txtToDate.Text = lastDate.ToString("dd/MM/yyyy");
                createStatusDll();
                dtContents = new DataTable();
                
                if (Request.QueryString["id"] != null && Request.QueryString["id"].Length > 0)
                {
                  
                }
                this.grvPO.DataSource = null;
                this.grvPO.DataBind();
              
            }
        }

        private void createStatusDll() {
            DataTable dt = new DataTable();
            dt.Columns.Add("Code");
            dt.Columns.Add("Name");
            dt.Rows.Add("-1", "All");
            dt.Rows.Add("0", "Not Submited");
            dt.Rows.Add("1", "Pending");
            dt.Rows.Add("2", "Approved");
            dt.Rows.Add("3", "Rejected");

            ddlStatus.DataSource = dt;
            ddlStatus.DataTextField = "Name";
            ddlStatus.DataValueField = "Code";
            ddlStatus.DataBind();
        }

        protected void btn_Filter_Click(object sender, EventArgs e)
        {

            string sql = "select ROW_NUMBER() OVER(ORDER BY gs.GeneralID DESC) AS No, gs.GeneralID, gs.ServiceDate, ";
            sql += " ws.SeqNo, ws.VIN, ws.CustomerName, ws.FailureDate, ws.Model, ws.EngineNumber,  ";
            sql += " ConditionCode, ws.RegistrationNum, gs.Status,  ";
            sql += " case gs.Status when 0 then 'Not Submited' when 1 then 'Pending' when 2 then 'Approved'  ";
            sql += " when 3 then 'Rejected' else '' end StatusName ";
            sql += " from U_GeneralService gs  ";
            sql += " join U_WSC ws on gs.GeneralID = ws.GeneralID where gs.JobKind = '004' ";
            sql += " AND gs.DealerCode = '" + Session[Utils.AppConstants.ID_Dealer] + "'";
            if (ddlStatus.SelectedValue != "-1")
            {
                sql += " AND gs.Status = " + ddlStatus.SelectedValue;
            }

            Services sv = new Services();
            DataSet ds = sv.ExecuteQuery("DEALER", sql);
            grvPO.DataSource = ds.Tables[0];
            grvPO.DataBind();
        }

        protected void btn_Submit_Click(object sender, EventArgs e)
        {
            string aa = "alo alo";
        }

        protected void Button1_Click(object sender, EventArgs e)
        {

        }
        protected void grdItem_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("onmouseover", "MouseEvents(this, event)");
                e.Row.Attributes.Add("onmouseout", "MouseEvents(this, event)");
                e.Row.Attributes["style"] = "cursor:pointer";
            }
        }

        public void GridView1_RowCommand(Object sender, GridViewCommandEventArgs e)
        {

            // If multiple buttons are used in a GridView control, use the

            // CommandName property to determine which button was clicked.

            if (e.CommandName == "EditMe")
            {


            }
        }

    }
}